package com.zhuo.project.hms.service.impl;

import java.util.List;

import com.zhuo.common.utils.DateUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.hms.mapper.ZzClinicRefDepotMapper;
import com.zhuo.project.hms.domain.ZzClinicRefDepot;
import com.zhuo.project.hms.service.IZzClinicRefDepotService;

/**
 * 诊所仓库关系信息Service业务层处理
 *
 * @author zhuo
 * @date 2020-03-21
 */
@Service
public class ZzClinicRefDepotServiceImpl implements IZzClinicRefDepotService {
    @Autowired
    private ZzClinicRefDepotMapper zzClinicRefDepotMapper;

    /**
     * 查询诊所仓库关系信息
     *
     * @param id 诊所仓库关系信息ID
     * @return 诊所仓库关系信息
     */
    @Override
    public ZzClinicRefDepot selectZzClinicRefDepotById(Long id) {
        return zzClinicRefDepotMapper.selectZzClinicRefDepotById(id);
    }

    @Override
    public ZzClinicRefDepot selectZzClinicRefDepotByDepotCodeAndClinicCode(String depotCode, String clinicCode) {
        ZzClinicRefDepot zzClinicRefDepot = new ZzClinicRefDepot();
        zzClinicRefDepot.setClinicCode(clinicCode);
        zzClinicRefDepot.setDepotCode(depotCode);
        List<ZzClinicRefDepot> list = selectZzClinicRefDepotList(zzClinicRefDepot);
        return list.get(0);
    }

    /**
     * 查询诊所仓库关系信息列表
     *
     * @param zzClinicRefDepot 诊所仓库关系信息
     * @return 诊所仓库关系信息
     */
    @Override
    public List<ZzClinicRefDepot> selectZzClinicRefDepotList(ZzClinicRefDepot zzClinicRefDepot) {
        return zzClinicRefDepotMapper.selectZzClinicRefDepotList(zzClinicRefDepot);
    }

    /**
     * 新增诊所仓库关系信息
     *
     * @param zzClinicRefDepot 诊所仓库关系信息
     * @return 结果
     */
    @Override
    public int insertZzClinicRefDepot(ZzClinicRefDepot zzClinicRefDepot) {
        ZzClinicRefDepot filter = new ZzClinicRefDepot();
        filter.setClinicCode(zzClinicRefDepot.getClinicCode());
        filter.setDepotCode(zzClinicRefDepot.getDepotCode());
        List<ZzClinicRefDepot> filterList = zzClinicRefDepotMapper.selectZzClinicRefDepotList(filter);
        if (null != filterList && filterList.size() > 0) {
            return -1;
        }
        zzClinicRefDepot.setCreateTime(DateUtils.getNowDate());
        zzClinicRefDepot.setCreateBy(SecurityUtils.getUsername());
        return zzClinicRefDepotMapper.insertZzClinicRefDepot(zzClinicRefDepot);
    }

    /**
     * 修改诊所仓库关系信息
     *
     * @param zzClinicRefDepot 诊所仓库关系信息
     * @return 结果
     */
    @Override
    public int updateZzClinicRefDepot(ZzClinicRefDepot zzClinicRefDepot) {
        ZzClinicRefDepot filter = new ZzClinicRefDepot();
        filter.setClinicCode(zzClinicRefDepot.getClinicCode());
        filter.setDepotCode(zzClinicRefDepot.getDepotCode());
        List<ZzClinicRefDepot> filterList = zzClinicRefDepotMapper.selectZzClinicRefDepotList(filter);
        if (null != filterList && filterList.size() !=1) {
            return -1;
        }
        zzClinicRefDepot.setUpdateTime(DateUtils.getNowDate());
        zzClinicRefDepot.setUpdateBy(SecurityUtils.getUsername());
        return zzClinicRefDepotMapper.updateZzClinicRefDepot(zzClinicRefDepot);
    }

    /**
     * 批量删除诊所仓库关系信息
     *
     * @param ids 需要删除的诊所仓库关系信息ID
     * @return 结果
     */
    @Override
    public int deleteZzClinicRefDepotByIds(Long[] ids) {
        return zzClinicRefDepotMapper.deleteZzClinicRefDepotByIds(ids);
    }

    /**
     * 删除诊所仓库关系信息信息
     *
     * @param id 诊所仓库关系信息ID
     * @return 结果
     */
    @Override
    public int deleteZzClinicRefDepotById(Long id) {
        return zzClinicRefDepotMapper.deleteZzClinicRefDepotById(id);
    }
}
